package com.devshephard.jucks.FunctionInterface;

import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;

public class FuncInterface {
    public static void main(String[] args) {

        /**
         *    函数式接口
         */
        // 普通函数式接口
        Function<String,Integer> function_01  = new Function<String, Integer>() {
            @Override
            public Integer apply(String s) {
                return 1024;
            }
        };
        System.out.println(function_01.apply("普通函数式接口"));

        //使用lamdba简化
        Function<String,Integer> function_L01 = (str) -> { return 10241; };
        System.out.println(function_L01.apply("简化普通函数式接口"));




        //断言式接口
        Predicate<String> predicate_01 = new Predicate<String>() {
            @Override
            public boolean test(String s) {
                return false;
            }
        };
        System.out.println(predicate_01.test("普通断言式接口"));

        //使用lamdba简化
        Predicate<String> predicate_L01 = (str) -> { return true; };
        System.out.println(predicate_L01.test("函数式简化断言式接口"));





        //消费型接口
        Consumer consumer_01 = new Consumer() {
            @Override
            public void accept(Object o) {
                System.out.println((Integer) o) ;
            }
        };
        consumer_01.accept(123);

        //使用lamdba简化
        Consumer consumer_L01 = (o) -> {
            System.out.println((Integer) o) ;
        };
        consumer_L01.accept(456);






        //供给型接口
        Supplier<String> supplier_01 = new Supplier<String>() {
            @Override
            public String get() {
              return "123";
            };
        };
        System.out.println(supplier_01.get());

        //使用lamdba简化
        Supplier<Integer> supplier_L01 = () -> {
            return 1024;
        };
        System.out.println(supplier_L01.get());
    }
}
